<?php

/**
 * This is the model class for table "volunteer".
 *
 * The followings are the available columns in table 'volunteer':
 * @property integer $id
 * @property string $volunteer_fname
 * @property string $volunteer_lname
 * @property integer $volunteer_age
 * @property string $volunteer_gender
 * @property string $volunteer_address
 * @property string $volunteer_birthdate
 * @property string $volunteer_picture
 * @property string $volunteer_status
 * @property integer $volunteer_ContactNumber
 * @property string $volunteer_email
 * @property integer $mission_area_id
 * @property integer $donation_id
 *
 * The followings are the available model relations:
 * @property Donation $donation
 * @property MissionArea $missionArea
 */
class Volunteer extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Volunteer the static model class
	 */
	 
	    
        public function getNames()
        {
                        return $this->lname.', '. $this->fname.' '. $this->mname;
        }

        const s='Single';
        const w='Widowed';
        const m='Merried';
        const se='Separated';
        const a='Annulled';

        const fe='Female';
        const ma='Male';
        
        public function getGenderOptions()
        {
                return array(
                        self::ma=>'Male',
                        self::fe=>'Female',
                );
        }
        
        public function getCivilStatusOption()
        {
                return array(
                        self::s=>'Single',
                        self::w=>'Widowed',
                        self::m=>'Married',
                        self::se=>'Separated',
                        self::a=>'Annulled',
                );
        }
		
		public function actionloadImage($id)
    {
        $model=$this->loadModel($id);
        $this->renderPartial('image', array(
            'model'=>$model
        ));
		
    }
		
		
		

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'volunteer';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('volunteer_fname, volunteer_address, volunteer_lname, mission_area_id, donation_id', 'required'),
			array('volunteer_age, volunteer_ContactNumber',  'numerical', 'integerOnly'=>true),
			array('volunteer_fname, volunteer_lname, volunteer_address,  volunteer_email', 'length', 'max'=>45),
			array('volunteer_age', 'length', 'max'=>2),
			array('volunteer_status, volunteer_picture, volunteer_gender, volunteer_birthdate', 'safe'),
			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.
			// Please remove those attributes that should not be searched.
			array('id, volunteer_fname, volunteer_lname, volunteer_age, volunteer_gender, volunteer_address, volunteer_birthdate, volunteer_picture, volunteer_status, volunteer_ContactNumber, volunteer_email, mission_area_id, donation_id', 'safe', 'on'=>'search'),
			array('volunteer_picture', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'on'=>'update'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'donation' => array(self::BELONGS_TO, 'Donation', 'donation_id'),
			'missionArea' => array(self::BELONGS_TO, 'MissionArea', 'mission_area_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'volunteer_fname' => 'First Name',
			'volunteer_lname' => 'Last Name',
			'volunteer_age' => 'Age',
			'volunteer_gender' => 'Gender',
			'volunteer_address' => ' Address',
			'volunteer_birthdate' => 'Birthdate',
			'volunteer_picture' => ' Picture',
			'volunteer_status' => 'Marital Status',
			'volunteer_ContactNumber' => 'Contact Number',
			'volunteer_email' => 'Email Address',
			'mission_area_id' => 'Mission Area',
			'donation_id' => 'Donation',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('volunteer_fname',$this->volunteer_fname,true);
		$criteria->compare('volunteer_lname',$this->volunteer_lname,true);
		$criteria->compare('volunteer_age',$this->volunteer_age);
		$criteria->compare('volunteer_gender',$this->volunteer_gender,true);
		$criteria->compare('volunteer_address',$this->volunteer_address,true);
		
		$criteria->compare('volunteer_picture',$this->volunteer_picture,true);
		$criteria->compare('volunteer_status',$this->volunteer_status,true);
		$criteria->compare('volunteer_ContactNumber',$this->volunteer_ContactNumber);
		$criteria->compare('volunteer_email',$this->volunteer_email,true);
		$criteria->compare('mission_area_id',$this->mission_area_id);
		$criteria->compare('donation_id',$this->donation_id);
		

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}
